package com.cn.appcore.ext

import com.cn.appcore.constant.CustConstant
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.flyco.tablayout.listener.CustomTabEntity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.coroutineScope


suspend fun executeResponse(
    response: BaseResponse<Any>,
    successBlock: suspend CoroutineScope.() -> Unit,
    againLoginBlock: suspend CoroutineScope.() -> Unit,
    errorBlock: suspend CoroutineScope.() -> Unit,

) {
    coroutineScope {
        if (response.code == CustConstant.HTTP_BTC_CODE_SUCCESS) {
            successBlock()
        } else if (response.code == CustConstant.LOGON_FAILURE ) {
            againLoginBlock()
        } else {
            errorBlock()
        }
    }
}
suspend fun catchResponse(
    catchBlock: suspend CoroutineScope.() -> Unit
) {
    coroutineScope {
        catchBlock()
    }
}
//list
suspend fun executeListResponse(
    response: BaseListResponse<Any>,
    successBlock: suspend CoroutineScope.() -> Unit,
    againLoginBlock: suspend CoroutineScope.() -> Unit,
    errorBlock: suspend CoroutineScope.() -> Unit
) {
    coroutineScope {
        if (response.code == CustConstant.HTTP_BTC_CODE_SUCCESS) {
            successBlock()
        } else if (response.code == CustConstant.LOGON_FAILURE ) {
            againLoginBlock()
        } else {
            errorBlock()
        }
    }
}

class TabEntity(var title: String, var selectedIcon: Int, var unSelectedIcon: Int) :
    CustomTabEntity {
    override fun getTabTitle(): String {
        return title
    }

    override fun getTabSelectedIcon(): Int {
        return selectedIcon
    }

    override fun getTabUnselectedIcon(): Int {
        return unSelectedIcon
    }
}






